#ifndef _COMMON_H
#define _COMMON_H
struct IPRule {
    char name[7];
    unsigned int saddr;
    unsigned int smask;
    unsigned int daddr;
    unsigned int dmask;
    unsigned int sport; // 源端口范围 高2字节为最小 低2字节为最大
    unsigned int dport; // 目的端口范围 同上
    u_int8_t protocol;
    unsigned int action;
    unsigned int log;
    struct IPRule* nx;
    struct IPRule* pre;
};
struct NATRecord { // NAT 记录 or 规则(源IP端口转换)
    unsigned int saddr; // 记录：原始IP | 规则：原始源IP
    unsigned int smask; // 记录：无作用  | 规则：原始源IP掩码
    unsigned int daddr; // 记录：转换后的IP | 规则：NAT 源IP

    unsigned short sport; // 记录：原始端口 | 规则：最小端口范围
    unsigned short dport; // 记录：转换后的端口 | 规则：最大端口范围
    unsigned short nowPort; // 记录：当前使用端口 | 规则：无作用
    struct NATRecord* nx;
};

struct cmdRequest {
    unsigned int tp;
    char ruleName[10];
    union {
         struct IPRule ipRule;
          struct NATRecord natRule;
        unsigned int defaultAction;
        unsigned int num;
    } msg;
};
struct KernelResponse {
    int rsplen; // <0 代表请求失败，失败码; >=0 代表body长度
    void *data; // 回应包指针，记得free
    int arrlen;//0直接打印有元素特殊处理
};

struct ConnLog {
    unsigned int saddr;
    unsigned int daddr;
    unsigned short sport;
    unsigned short dport;
    u_int8_t protocol;
    int natType;
    struct NATRecord nat; // NAT记录
};


#define REQ_GETAllIPRules 1
#define REQ_ADDIPRule 2
#define REQ_DELIPRule 3


#define REQ_ADDNATRule 4
#define REQ_GETNATRules 5
#define REQ_SETdefault 7
#define REQ_GETAllConns 6
#define NAT_TYPE_NO 0
#define NAT_TYPE_SRC 1
#define NAT_TYPE_DEST 2
#define uint8_t unsigned char
#define NETLINK_MYFW 17
#define MAX_PAYLOAD (1024 * 256)
#define MAXRuleNameLen 6




#endif


